﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using WenslyWuLib.Common.DynamicEffect;
using MTodo.Model;

namespace MTodo
{
    public partial class NewMemo : UserControl
    {
        public NewMemo()
        {
            InitializeComponent();
        }

        #region Properties

        /// <summary>
        /// Gets or Sets GroupID
        /// </summary>
        public Guid GroupID { get; set; }

        /// <summary>
        /// Gets or Sets Items
        /// </summary>
        public MemoItem Item { get; set; } 

        #endregion

        #region Methods
        /// <summary>
        /// Show Pop View
        /// </summary>
        public void ShowDiaglog()
        {
            ClearView();
            Storyboard sb = AnimationProvider.GetSimpleAnimation(800, 0, 0.5,new PropertyPath(Canvas.TopProperty));
            Storyboard.SetTarget(sb, DiagRoot);
            sb.Begin();
        }

        /// <summary>
        /// Clear the view values
        /// </summary>
        public void  ClearView()
        {
            this.txtMemo.Text=string.Empty;
            this.txtTitle.Text = string.Empty;
        }
        /// <summary>
        /// Hidden Pop View
        /// </summary>
        public void HiddenDialog(Action completeHandler )
        {
            Storyboard sb = AnimationProvider.GetSimpleAnimation(0, 800, 0.5, new PropertyPath(Canvas.TopProperty));
            Storyboard.SetTarget(sb, DiagRoot);
            sb.Completed += new EventHandler(new Action<object, EventArgs>((o, e) =>
              {
                  if (completeHandler != null)
                      completeHandler();
              }));
            sb.Begin();
        }

        /// <summary>
        /// Get New Objects
        /// </summary>
        /// <returns></returns>
        public MemoItem GetNewItemObject()
        {
            Item = new MemoItem() { ItemID = Guid.NewGuid(), GroupID = GroupID };
            Item.MemoText = this.txtMemo.Text.Trim();
            Item.MemoTitle = this.txtTitle.Text.Trim();
            if (string.IsNullOrWhiteSpace(Item.MemoText) && string.IsNullOrWhiteSpace(Item.MemoTitle))
            {
                return null;
            }
            return Item;
        }

        #endregion
    }
}
